package com.yuanchu.store.controller;

import  com.yuanchu.common.utils.R;
import com.yuanchu.store.dto.WeChatModel;
import com.yuanchu.store.entity.YoshopUserEntity;
import com.yuanchu.store.service.LoginService;
import com.yuanchu.store.service.YoshopUserOauthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-01-28 17:10
 */
@Slf4j
@RestController
public class ShopLoginController {

    //在开发者平台中获取APPID和APPSECRET
    private static final String APPID= "wx1fe248dc8d5b9858";
    private static final String APPSECRET = "d0852a0f67d6228425c1fad9f748a072";

    @Resource
    private YoshopUserOauthService userOauthService;
    @Resource
    private LoginService loginService;
    // @Resource
    // private RestTemplate restTemplate;


    /**
     * 微信登录
     * @param form
     * code: "0b38Ba1w3IqB823Ahi1w3tUpzt08Ba16"
     * oauth: "MP-WEIXIN"
     * userInfo: {}
     * @return token
     */
    @PostMapping("/passport/loginMpWx")
    public R loginMpWx(@RequestBody /*Map<String, Object>*/ WeChatModel form) {
        WeChatModel.FormParams params = form.getForm();
        String code = params.getPartyData().getCode();
        String oauth = params.getPartyData().getOauth();
        YoshopUserEntity userInfo = params.getPartyData().getUserInfo();
        Map<String, Object> map = loginService.login(code, oauth, userInfo);
        return R.ok().put("data", map);
    }
}
